//
// Created by lz on 3/16/21.
//

#ifndef MYWEBLIB_NET_HTTPRESPONSE_H_
#define MYWEBLIB_NET_HTTPRESPONSE_H_

#include "base/copyable.h"
#include "base/Types.h"

#include <map>

namespace lzweb
{
	namespace net
	{
		class Buffer;
		class HttpResponse : public lzweb::copyable
		{
		 public:
			enum HttpStatusCode
			{
				kUnknown,
				k200OK = 200,
				k301MovedPermanently = 301,
				k400BadRequest = 400,
				k404NotFound = 404,
			};

			explicit HttpResponse(bool close)
				: statusCode_(kUnknown),
				  closeConnection_(close)
			{

			}

			void setStatusCode(HttpStatusCode code)
			{ statusCode_ = code; }

			void setStatusMessage(const string& message)
			{ statusMessage_ = message; }

			void setCloseConnection(bool on)
			{ closeConnection_ = on; }

			bool closeConnection() const
			{ return closeConnection_; }

			void setContentType(const string& contentType)
			{
				addHeader("Content-Type", contentType);
			}
			//FIXME : replace string with StringPiece
			void addHeader(const string& key, const string& value)
			{
				headers_[key] = value;
			}

			void setBody(const string& body)
			{
				body_ = body;
			}

			void appendToBuffer(Buffer* output) const;



		 private:

			std::map<string, string> headers_;  //头部信息
			HttpStatusCode statusCode_;   //状态码
			//FIXME: add http version
			string statusMessage_;		// 状态信息
			bool closeConnection_;      // 是否保持连接
			string body_;				//主体信息
		};
	} //namespace net
}// namespace lzweb


#endif //MYWEBLIB_NET_HTTPRESPONSE_H_
